home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 431_01 / rport.c < prev    next >
Text File  |  1994-10-07  |  2KB  |  83 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dos.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6.  
  7. #include "ifs.h"
  8. #include "rifs.h"
  9. #include "rclient.h"
  10. #include "local.h"
  11.  
  12. void ShowUse(char *err)
  13. {
  14.   if (err)
  15.     printf("Error: %s\n", err);
  16.   printf("Use:\n"
  17.          "  rport [local [TO server | REMOVE]]\n"
  18.          "\n"
  19.          "Examples:\n"
  20.          "  rport 1 to 1\n"
  21.          "    redirects output from LPT1 to server LPT1\n"
  22.          "  rport 1 remove\n"
  23.          "    removes redirection of LPT1\n"
  24.          "  rport\n"
  25.          "    show current redirections\n");
  26.   exit(1);
  27. }
  28.  
  29. int main(int argc, char **argv)
  30. {
  31.   int RIFS=FindRIFS();
  32.   struct REGPACK regs;
  33.   BYTE *xlate;
  34.   int   local=0,
  35.         remote=0;
  36.  
  37.   if (RIFS) {
  38.     regs.r_ax=0x0000;
  39.     intr(RIFS, ®s);
  40.   }
  41.   if (!RIFS || (regs.r_ax != 0x1234)) {
  42.     fprintf(stderr, "RCLIENT not loaded");
  43.     exit(1);
  44.   }
  45.   regs.r_ax=RCLIENT_GETPORTXLAT;
  46.   intr(RIFS, ®s);
  47.   xlate=MK_FP(regs.r_es, regs.r_bx);
  48.  
  49.   if (argc == 1) {
  50.     int ii;
  51.     printf("Current port mapping (locate --> server):\n");
  52.     for (ii=0; ii < 3;  ii++) {
  53.       if (!xlate[ii])
  54.         printf("\t%d --> local\n", ii+1);
  55.       else
  56.         printf("\t%d --> %d\n", ii+1, xlate[ii]);
  57.     }
  58.   } else {
  59.     local=atoi(argv[1])-1;
  60.     if ((local < 0) || (local > 2))
  61.       ShowUse("local port must be 1, 2, or 3");
  62.  
  63.     if (stricmp(argv[2], "to") == 0) {
  64.       if (argc != 4)
  65.         ShowUse("no argument for TO");
  66.       else {
  67.         remote=atoi(argv[3]);
  68.         if ((remote < 1) || (remote > 3))
  69.           ShowUse("remote port must be 1, 2, or 3");
  70.       }
  71.       xlate[local]=remote;
  72.     } else if (stricmp(argv[2], "remove") == 0) {
  73.       if (argc != 3)
  74.         ShowUse("too many parameters");
  75.       else
  76.         xlate[local]=0;
  77.     } else
  78.       ShowUse(NULL);
  79.   }
  80.  
  81.   return 0;
  82. }
  83.